namespace ASPNET.StarterKit.IssueTracker.BusinessLogicLayer
{
    using ASPNET.StarterKit.IssueTracker.DataAccessLayer;
    using System;

    public class RelatedIssue
    {
        private DateTime _DateCreated;
        private int _IssueId;
        private string _Title;

        public RelatedIssue(int issueId, string title, DateTime dateCreated)
        {
            this._IssueId = issueId;
            this._Title = title;
            this._DateCreated = dateCreated;
        }

        public static int CreateNewChildIssue(int primaryIssueId, int secondaryIssueId)
        {
            if (primaryIssueId == secondaryIssueId)
            {
                return 0;
            }
            if (primaryIssueId <= DefaultValues.GetIssueIdMinValue())
            {
                throw new ArgumentOutOfRangeException("primaryIssueId");
            }
            if (secondaryIssueId <= DefaultValues.GetIssueIdMinValue())
            {
                throw new ArgumentOutOfRangeException("secondaryIssueId");
            }
            return DataAccessLayerBaseClassHelper.GetDataAccessLayer().CreateNewChildIssue(primaryIssueId, secondaryIssueId);
        }

        public static int CreateNewParentIssue(int primaryIssueId, int secondaryIssueId)
        {
            if (primaryIssueId == secondaryIssueId)
            {
                return 0;
            }
            if (primaryIssueId <= DefaultValues.GetIssueIdMinValue())
            {
                throw new ArgumentOutOfRangeException("primaryIssueId");
            }
            if (secondaryIssueId <= DefaultValues.GetIssueIdMinValue())
            {
                throw new ArgumentOutOfRangeException("secondaryIssueId");
            }
            return DataAccessLayerBaseClassHelper.GetDataAccessLayer().CreateNewParentIssue(primaryIssueId, secondaryIssueId);
        }

        public static int CreateNewRelatedIssue(int primaryIssueId, int secondaryIssueId)
        {
            if (primaryIssueId == secondaryIssueId)
            {
                return 0;
            }
            if (primaryIssueId <= DefaultValues.GetIssueIdMinValue())
            {
                throw new ArgumentOutOfRangeException("primaryIssueId");
            }
            if (secondaryIssueId <= DefaultValues.GetIssueIdMinValue())
            {
                throw new ArgumentOutOfRangeException("secondaryIssueId");
            }
            return DataAccessLayerBaseClassHelper.GetDataAccessLayer().CreateNewRelatedIssue(primaryIssueId, secondaryIssueId);
        }

        public static bool DeleteChildIssue(int primaryIssueId, int secondaryIssueId)
        {
            if (primaryIssueId <= DefaultValues.GetIssueIdMinValue())
            {
                throw new ArgumentOutOfRangeException("primaryIssueId");
            }
            if (secondaryIssueId <= DefaultValues.GetIssueIdMinValue())
            {
                throw new ArgumentOutOfRangeException("secondaryIssueId");
            }
            return DataAccessLayerBaseClassHelper.GetDataAccessLayer().DeleteChildIssue(primaryIssueId, secondaryIssueId);
        }

        public static bool DeleteParentIssue(int primaryIssueId, int secondaryIssueId)
        {
            if (primaryIssueId <= DefaultValues.GetIssueIdMinValue())
            {
                throw new ArgumentOutOfRangeException("primaryIssueId");
            }
            if (secondaryIssueId <= DefaultValues.GetIssueIdMinValue())
            {
                throw new ArgumentOutOfRangeException("secondaryIssueId");
            }
            return DataAccessLayerBaseClassHelper.GetDataAccessLayer().DeleteParentIssue(primaryIssueId, secondaryIssueId);
        }

        public static bool DeleteRelatedIssue(int primaryIssueId, int secondaryIssueId)
        {
            return DataAccessLayerBaseClassHelper.GetDataAccessLayer().DeleteRelatedIssue(primaryIssueId, secondaryIssueId);
        }

        public static RelatedIssueCollection GetChildIssues(int issueId)
        {
            if (issueId <= DefaultValues.GetIssueIdMinValue())
            {
                throw new ArgumentOutOfRangeException("issueId");
            }
            return DataAccessLayerBaseClassHelper.GetDataAccessLayer().GetChildIssues(issueId);
        }

        public static RelatedIssueCollection GetParentIssues(int issueId)
        {
            if (issueId <= DefaultValues.GetIssueIdMinValue())
            {
                throw new ArgumentOutOfRangeException("issueId");
            }
            return DataAccessLayerBaseClassHelper.GetDataAccessLayer().GetParentIssues(issueId);
        }

        public static RelatedIssueCollection GetRelatedIssues(int issueId)
        {
            if (issueId <= DefaultValues.GetIssueIdMinValue())
            {
                throw new ArgumentOutOfRangeException("issueId");
            }
            return DataAccessLayerBaseClassHelper.GetDataAccessLayer().GetRelatedIssues(issueId);
        }

        public DateTime DateCreated
        {
            get
            {
                return this._DateCreated;
            }
        }

        public int IssueId
        {
            get
            {
                return this._IssueId;
            }
        }

        public string Title
        {
            get
            {
                if ((this._Title == null) || (this._Title.Length == 0))
                {
                    return string.Empty;
                }
                return this._Title;
            }
            set
            {
                this._Title = value;
            }
        }
    }
}

